<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>保单结算 管理</title>
    <style type="text/css">
        .searchArea .fieldBox .label {
            width: 65px;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
        }
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div>
        <div id="pageInTab" class="pageInTab">
            <div tabid="insPlcStlMgr" title="保单结算管理" lselected="true">
                <div class="searchArea">
                    <form id="searchBar">
                        <div class="fieldset1 clearFix">
                            <div class="fieldBox">
                                <div class="label">保险公司</div>
                                <div class="field">
                                    <input name="insCompId" id="insCompId" data-value="" placeholder="请选择"
                                           ltype="combobox">
                                </div>
                            </div>
                            <div class="fieldBox">
                                <div class="label">保险支公司</div>
                                <div class="field">
                                    <input name="insCompSubNm" id="insCompSubNm" data-value="" type="text" class="ui-textbox">
                                </div>
                            </div>
                            <div class="fieldBox">
                                <div class="label">起保日期</div>
                                <div class="field">
                                    <input ligerui="width: 82" name="plcBgTmStart" id="plcBgTmStart" type="text"
                                           class="ui-datepicker" value="">
                                    -
                                    <input ligerui="width: 82" name="plcBgTmEnd" id="plcBgTmEnd" type="text"
                                           class="ui-datepicker" value="">
                                </div>
                            </div>
                            <div class="fieldBox">
                                <div class="label">客户经理</div>
                                <div class="field">
                                    <input name="cstMgrNm" id="cstMgrNm" data-value="" type="text" class="ui-textbox">
                                </div>
                            </div>
                            <div class="fieldBox">
                                <div class="label">事业部</div>
                                <div class="field">
                                    <input name="buOrgCd" id="buOrgCd" data-value="" placeholder="请选择" ltype="combobox">
                                </div>
                            </div>

                            <div class="fieldBox">
                                <div class="label">结算状态</div>
                                <div class="field">
                                    <input name="stlStsCd" id="stlStsCd" data-value="${stlStsCd}" placeholder="请选择" ltype="combobox">
                                </div>
                            </div>

                            <div class="fieldBox">
                                <div class="label">购买方式</div>
                                <div class="field">
                                    <input name="buyWayCd" id="buyWayCd" data-value="" placeholder="请选择" ltype="combobox">
                                </div>
                            </div>
                            <div class="fieldBox">
                                <div class="label">保单号</div>
                                <div class="field">
                                    <input name="plcNo" id="plcNo" data-value="" type="text" class="ui-textbox">
                                </div>
                            </div>
                            <div class="fieldBox">
                                <div class="label">客户名称</div>
                                <div class="field">
                                    <input name="cstNm" id="cstNm" data-value="" type="text" class="ui-textbox">
                                </div>
                            </div>
                            <div class="fieldBox">
                                <div class="label">支付表号</div>
                                <div class="field">
                                    <input name="paySchNo" id="paySchNo" data-value="" type="text" class="ui-textbox">
                                </div>
                            </div>
                            <div class="fieldBox">
                                <div class="label">保险种类</div>
                                <div class="field">
                                    <input name="insTypCd" id="insTypCd" data-value="" placeholder="请选择" ltype="combobox">
                                </div>
                            </div>

                            <div class="clearFix"></div>
                            <div class="btnsBox">
                                <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                                <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                                <span id="stlBtn" class="sq-button sq-button-round">结算</span>
                                <%--<span id="downloadBtn" class="sq-button sq-button-round">导出</span>--%>
                                <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="sqPanel" style="margin-bottom: 0;">
                    <div class="sqPanel_head">
                        <table class="table_full">
                            <tr>
                                <td><b>保费总金额合计(元): </b><span id="ttlFeeAmt"/></td>
                                <td><b>结算总金额合计(元): </b><span id="ttlStlAmt"/></td>
                            </tr>
                        </table>
                    </div>
                    <div class="sqPanel_body">
                        <div id="ligergrid1" class="sq-grid"></div>
                    </div>
                </div>
            </div>
            <div tabid="insStlRecMgr" title="结算记录管理" lselected="false">
                <iframe frameborder="0" name="insStlRecMgr" id="insStlRecMgr" src=""></iframe>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    var grid = null;
    var pageInApp = {};
    var loadedTabs = [];
    var form=null;
    $(function () {
        pageInTab = $("#pageInTab").ligerTab({
            height: 'auto',
            contextmenu: false,
            minIframeHeight: GET_minIframeHeight(),
            onAfterSelectTabItem: function (tabid) {
                if (loadedTabs.indexOf(tabid) < 0) {
                    //获取结算记录
                    loadedTabs.push(tabid);
                    switch (tabid) {
                        case "insStlRecMgr":
                            pageInTab.setTabItemSrc(tabid, "<%=path%>/insurance/insPlcStl/toStlRecListPage.do");
                            break;
                    }
                }
                SetIframe_height();
            }
        });

        $.extend(true, pageInApp, {
            pageInTab: pageInTab
        });

        $("#stlStsCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        $("#buOrgCd").ligerComboBox({
            valueField: 'orgCd',
            textField: 'orgNm'
        });
        $("#buyWayCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        $("#insCompId").ligerComboBox({
            valueField: 'id',
            textField: 'compNm',
            autocomplete: function (e){
                filter_autoComboboxData(e.key, this);
                e.show();
            },
        });
        $("#insTypCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });

        form=$("#searchBar").ligerForm();

        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/insurance/insPlcStl/initStlList.do',
            method: 'get',
            parms:getSearchParams(),
            columns: [
                {display: '事业部', name: 'buOrgCdNm', minWidth: 80, align: 'left', enabledSort: false},
                {display: '客户经理', name: 'cstMgrNm', minWidth: 80, align: 'left', enabledSort: false},
                {display: '支付表号', name: 'paySchNo', width: 160, align: 'left', enabledSort: false},
                {
                    display: '保单号', name: 'plcNo', minWidth: 100, align: 'left', enabledSort: false,
                    render: function (rowdata, index, value) {
                        if(!value||value==null||value=='null'){
                            return '<a href="javascript:;" onclick="queryPlcDtl('+rowdata.id+')">保单</a>';
                        }
                        return '<a onclick="queryPlcDtl(' + rowdata.id + ');">' + rowdata.plcNo + '</a>';
                    }
                },
                {display: '客户名称', name: 'cstNm', minWidth: 80, align: 'left', enabledSort: false},
                {display: '保险种类', name: 'insTypCdNm', minWidth: 80, align: 'left', enabledSort: false},
                {display: '保险公司', name: 'insCompNm', minWidth: 100, align: 'left', enabledSort: false},
                {display: '保险支公司', name: 'insCompSubNm', minWidth: 100, align: 'left', enabledSort: false},
                {display: '购买方式', name: 'buyWayCdNm', minWidth: 100, align: 'left', enabledSort: false},
                {display: '被保险人', name: 'insPerNm', minWidth: 100, align: 'left', enabledSort: false},
                {
                    display: '保费总金额(元)', name: 'insTtlFee', minWidth: 100, align: 'right', enabledSort: false,
                    render: function (rowdata) {
                        return '&yen;' + FormatMoney(rowdata.insTtlFee / 100);
                    }
                },
                {
                    display: '结算比例', name: 'stlRat', minWidth: 100, align: 'right', enabledSort: false,
                },
                {
                    display: '结算金额(元)', name: 'stlAmt', minWidth: 100, align: 'right', enabledSort: false,
                    render: function (rowdata) {
                        return '&yen;' + FormatMoney(rowdata.stlAmt / 100);
                    }
                },
                /*{display: '保单状态', name: 'plcStsCdNm', minWidth: 80, align: 'center', enabledSort: false},*/
                {display: '起保时间', name: 'plcBgTm', minWidth: 100, align: 'center', enabledSort: true, render: renderDate},
                /* {display: '保单结束时间', name: 'plcEndTm', minWidth: 100, align: 'left', enabledSort: true,render: renderDate}, */
                {display: '保单性质', name: 'plcPropCdNm', minWidth: 100, align: 'center', enabledSort: false},
                {display: '结算状态', name: 'stlStsCdNm', minWidth: 100, align: 'center', enabledSort: false},
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false
        });
        grid.setHeight(100);

        getTtlAmtSummary();//查询汇总值

        $("#pageloading").hide();

        //查询参数
        function getSearchParams(){
            var data = form.getData();
            return data;
        }

        /* 查询 */
        $("#searchBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
            getTtlAmtSummary();//查询汇总值
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            clearLigerForm("searchBar");
        });

        //结算
        $("#stlBtn").click(function (event) {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length == 0) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
                return;
            }
            var _ids = [];
            for (var index in selectedRows) {
                 if(selectedRows[index].stlStsCd!=20){
                     $.ligerDialog.SQalert({content: "请选择未结算保单进行结算汇总", SQ_type: "warning"});
                     return;
                 }
                _ids.push(selectedRows[index].id);
            }
            $.ligerDialog.confirm("是否确认对选中的保单进行结算汇总?", function (flag) {
                if (flag == false)return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {ids: JSON.stringify(_ids)},
                    url: '<%=path%>/insurance/insPlcStl/add.do',
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({
                            content: LogUtils.LOG_CMM_DATA_LOADING,
                            SQ_type: "waitting"
                        });
                    },
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.success == 1) {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                            grid.reload();
                        } else {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                        }
                    }
                });
            });

        });

        //导出
        $("#downloadBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType:'json',
                url: '<%=path%>/insurance/insPlcStl/exportStlList.do',
                data:data,
                beforeSend:function(){
                    wait_dialog=$.ligerDialog.SQalert({content: '正在导出...',SQ_type: "waitting"});
                },
                success:function(msg){
                    wait_dialog.close();
                    if(msg.success == 1){
                        window.open(msg.data);
                    }else{
                        $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                    }
                }
            });
        });

        liger.get("insTypCd").setData(${insTypCdList});
        liger.get("stlStsCd").setData(${stlStsCdList});
        liger.get("buOrgCd").setData(${buOrgCdList});
        liger.get("buyWayCd").setData(${buyWayCdList});
        liger.get("insCompId").setData(${insCompList});
        liger.get("insCompId").updateStyle();
    });

    function queryPlcDtl(id) {
        Add_navTab('InsPlcBscInfo_DTL_' + id, "保单详情", '<%=path%>/insurance/insPlcBscInfo/toDetailPage.do?id=' + id, null);
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

    //查询汇总
    function getTtlAmtSummary(){
        var data = form.getData();
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: data,
            url: '<%=path%>/insurance/insPlcStl/getTtlStlAmt.do',
            success: function (msg) {
                if (msg.success == 1) {
                    if(msg.data.TTL_FEE_AMT){
                        $("#ttlFeeAmt").text(FormatMoney(msg.data.TTL_FEE_AMT/100));
                    }else{
                        $("#ttlFeeAmt").text('¥0.00');
                    }
                    if(msg.data.TTL_STL_AMT) {
                        $("#ttlStlAmt").text(FormatMoney(msg.data.TTL_STL_AMT / 100));
                    }else{
                        $("#ttlStlAmt").text('¥0.00');
                    }
                }
            }
        });
    }

</script>

</body>
</html>
